<template>
	<view>
		<nav-back></nav-back>

		<view class="demand">
			<view class="title">
				<text>您的择偶要求 </text>
			</view>
			<view class="tip">最真实的自己，更快遇到最应该的那个人</view>

			<view class="age">
				<view class="label">
					<text>年龄</text> <text class="label1">{{ageString}}</text>
				</view>
				<SliderRange :min="18" :max="50" :value="ageRange" range :bar-height="5"
					active-color="rgba(156, 156, 255, 1)" @change="dragAge" />
				<view class="tip">
					<text>18</text> <text>50</text>
				</view>
			</view>

			<view class="height">
				<view class="label">
					<text>身高（cm）</text> <text class="label1">{{heightString}}</text>
				</view>
				<SliderRange :min="160" :max="200" :value="heightRange" range :bar-height="5"
					active-color="rgba(156, 156, 255, 1)" @change="dragHeight" />
				<view class="tip">
					<text>160</text> <text>200</text>
				</view>
			</view>

			<view class="income">
				<view class="label">
					<text>月收入（元）</text>
					<view class="open" @click="handleIncome">
						<text class="label1">{{income}}</text>
						<image src="/static/img/open.png" mode="" />
					</view>
				</view>
			</view>
			<view class="education">
				<view class="label">
					<text>学历</text>
				</view>
				<view class="box_list">
					<view v-for="(item,index) in educationList" class="box" :class="item.active?'active':''"
						@click="handleEducation(index)">
						{{item.name}}
					</view>
				</view>
			</view>
		</view>

		<u-popup closeable class="info-popup" :show="showIncome" mode='bottom' @close="closeIncome">
			<view class="my-popup">
				<view class="income_title">
					月收入
				</view>
				<picker-view @change="changeIncome" :value="incomeValue" class="my-picker-view">
					<picker-view-column>
						<view class="item" v-for="(item,index) in incomeList" :key="index">{{item}}</view>
					</picker-view-column>
				</picker-view>
				<button class="confirm" type="primary" @click="closeIncome">确认</button>
			</view>
		</u-popup>

		<button class="next" type="primary" @click="handleNext">下一步</button>


	</view>
</template>

<script>
	import request from '@/utils/request.js'
	import NavBack from '@/components/NavBack.vue'
	import SliderRange from '@/components/primewind-sliderrange/components/primewind-sliderrange/index.vue'

	export default {
		components: {
			NavBack,
			SliderRange
		},
		data() {
			return {
				ageRange: [23, 28],
				ageString: '',
				heightRange: [170, 175],
				heightString: '',
				showIncome: false,
				incomeList: ['2000及以下', '2000-4000元', '4000-6000元', '6000-8000', '8000及以上', '不限'],
				income: '',
				educationList: [{
						name: '中专',
						active: false
					},
					{
						name: '大专',
						active: false
					},
					{
						name: '本科',
						active: false
					},
					{
						name: '硕士',
						active: false
					},
					{
						name: '博士',
						active: false
					}
				],
				education: '',
				incomeValue: [5]
			}
		},
		onLoad() {
			this.ageString = this.ageRange.join('-'),
				this.heightString = this.heightRange.join('-'),
				this.income = this.incomeList[5]
		},
		methods: {
			dragAge(event) {
				console.log(event, 'dragAge');
				this.ageRange = event
				this.ageString = this.ageRange.join('-')
			},
			dragHeight(event) {
				console.log(event, 'dragHeight');
				this.heightRange = event
				this.heightString = this.heightRange.join('-')
			},
			handleIncome() {
				this.showIncome = true
			},
			changeIncome(event) {
				let current = event.detail.value[0]
				console.log(current, 'changeHouse');
				this.incomeValue[0] = current
				this.income = this.incomeList[current]
			},
			closeIncome() {
				this.showIncome = false
			},
			handleEducation(index) {
				this.educationList[index].active = !this.educationList[index].active
				let education = this.educationList.filter(item => {
					return item.active
				}).map(item => {
					return item.name
				})
				this.education = education.join(' | ')
				console.log(this.education, 'education');
			},
			handleNext() {
				if (!this.education) {
					uni.showToast({
						title: '请选择学历要求',
						icon: 'none',
						duration: 2000
					})
					return
				}
				let spouse = {}
				spouse.minAge = this.ageRange[0]
				spouse.maxAge = this.ageRange[1]
				spouse.minHeight = this.heightRange[0]
				spouse.maxHeight = this.heightRange[1]
				spouse.income = this.income
				spouse.education = this.education
				getApp().globalData.userInfo.spouse = spouse
				console.log(getApp().globalData.userInfo.spouse, 'spouse');
				uni.navigateTo({
					url: '/pages/userInfo/wxNumber/wxNumber'
				})
			},
		}
	}
</script>

<style lang="scss">
	@import "@/style/register.scss";

	.demand {
		height: 75vh;
		overflow: scroll;
	}
	.age,
	.height,
	.income,
	.education {
		margin-top: 5vh;
		font-weight: 500;

		.label,
		.tip {
			display: flex;
			justify-content: space-between;
		}

		.label1 {
			color: rgba(102, 102, 102, 1);
		}

		.van-slider {
			margin-top: 35rpx;
		}

		.tip text{
			font-size: 28rpx;
		}

		.open {
			display: flex;
			align-items: center;

			image {
				width: 32rpx;
				height: 32rpx;
			}
		}
	}

	.height {
		margin-top: 3vh;
	}


	.info-popup /deep/ .u-popup__content {
		.my-popup {
			height: 500rpx;
		}

		.my-picker-view {
			margin-top: 20rpx;
			height: 300rpx;
		}

		.income_title {
			font-size: 36rpx;
			font-weight: 500;
			text-align: center;
			margin-top: 30rpx;
		}

		button {
			width: 65%;
			position: absolute;
			bottom: 30rpx;
			left: 0;
			right: 0;
		}
	}

	.box_list {
		display: flex;
		flex-wrap: wrap;
		margin-top: 30rpx;

		.box {
			color: rgba(102, 102, 102, 1);
			font-size: 28rpx;
			padding: 15rpx 30rpx;
			margin-right: 10rpx;
			border-radius: 20rpx;
			background-color: #EDEDED;
		}

		.active {
			color: rgba(156, 156, 255, 1);
			background-color: #EBEBFF;
		}
	}
</style>